//
//  LoginPage.m
//  NewsReader
//
//  Created by zhouxiaobo on 15/11/2.
//  Copyright © 2015年 mapath. All rights reserved.
//

#import "LoginPage.h"
#import "FxLogin.h"
#import "UserInfo.h"

@implementation LoginPage

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = LoginTitle;
    [self setNavigationLeft:@"NavigationBack.png"];
    [self setNavigationRight:@"NavigationSquare.png"];
}

- (BOOL) checkValidate {
    BOOL flag = YES;
    
    if (_userName.text.length<=0 || _password.text.length<=0) {
        flag = NO;
        [self showIndicator:LoginCheckTip autoHide:YES afterDelay:YES];
    }
    return flag;
}

- (IBAction)doLoginEvent:(id)sender{
    
    if (![self checkValidate]) {
        return;
    }
    
    [self showIndicator:LoginingTip autoHide:NO afterDelay:NO];
    
    NSString *body = [NSString stringWithFormat:@"username=%@&password=%@",_userName.text,_password.text];
    
    NSDictionary *dictInfo = @{@"url":LoginURL,
                               @"body":body};
    _opertion = [[FxLogin alloc]initWithDelegate:self opInfo:dictInfo];
    [_opertion executeOp];
}

- (void)opFail:(NSString *)errorMessage {
    BASE_ERROR_FUN(errorMessage);
    
}

- (void)opSuccess:(UserInfo *)data {
    BASE_INFO_FUN(data.name);
    BASE_INFO_FUN(data.token);
}

@end
